//
//  NSDate+extend.m
//  mmbang
//
//  Created by 倪元政 on 2016/12/6.
//  Copyright © 2016年 iyaya. All rights reserved.
//

#import "NSDate+extend.h"

@implementation NSDate (extend)

-(NSInteger)dayIntervalFromDate:(NSDate *)fromDate{
    NSTimeInterval intervalSeconds = floor([self timeIntervalSinceDate:fromDate]);
    NSInteger daySeconds = 24*60*60;
    NSInteger days = intervalSeconds/daySeconds;
    return days;
}

-(void)getDateYear:(NSInteger *)year month:(NSInteger *)month day:(NSInteger *)day{
    NSCalendarUnit unitFlag = NSCalendarUnitYear|NSCalendarUnitMonth|NSCalendarUnitDay;
    NSCalendar *cal = [NSCalendar currentCalendar];
    NSDateComponents *comp = [cal components:unitFlag fromDate:self];
    *year = comp.year;
    *month = comp.month;
    *day = comp.day;
}

-(NSString *)yyyyMMddDateString{
    NSInteger year,month,day;
    [self getDateYear:&year month:&month day:&day];
    NSString *dateString = [NSString stringWithFormat:@"%04zd%02zd%02zd",year,month,day];
    return dateString;
    
}

@end
